<template>
  <div v-show="menuVisible">
    <div id="context-menu" class="menu">
      <slot></slot>
    </div>
  </div>
</template>
<script>
  export default {
    data(){
      return {
        menuVisible: false
      }
    },
    methods: {
      close() { // 取消鼠标监听事件 菜单栏
        this.menuVisible = false
        document.removeEventListener('click', this.foo)
      },
      show(MouseEvent,){
        this.menuVisible = true
        let menu = document.querySelector('#context-menu')
        document.addEventListener('click', this.close)
        menu.style.display = "block";
        menu.style.left = MouseEvent.clientX - 130 + 'px'
        menu.style.top = MouseEvent.clientY - 80 + 'px'
      },
    }
  }
</script>
<style lang="scss" scoped>
  .menu {
    height: inherit;
    position: absolute;
    border-radius: 4px;
    border: 1px solid #e8e8e8;
    background: #ffffff;
    z-index: 1000;
    .menu-item {
      list-style: none;
      line-height: 26px;
      padding: 0 20px;
      margin: 0;
      font-size: 14px;
      color: #606266;
      cursor: pointer;
      outline: none;
      &:hover {
        background: #e8e8e8;
      }
    }
  }
</style>
